package com.hgw.springsecurityjwtdemo02.controller;

import com.hgw.springsecurityjwtdemo02.common.ResponseResult;
import com.hgw.springsecurityjwtdemo02.domian.User;
import com.hgw.springsecurityjwtdemo02.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * Description: 认证模块
 * Data time:2022/9/1 14:48
 * Author:TQ-3038-HuangGongWei
 */
@RestController
@RequestMapping("auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        if (Objects.isNull(user) || Objects.isNull(user.getUserName()) || Objects.isNull(user.getPassword())) {
            return new ResponseResult(300, "用户密码不能为空");
        }
        return authService.login(user);
    }

    @RequestMapping("/logout")
    public ResponseResult logout() {
        return authService.logout();
    }
}
